package com.android.aiod.manager;

import android.os.Environment;
import android.text.TextUtils;
import com.android.aiod.bean.ConfigInfo;
import com.android.baselibrary.tool.Log;
import com.blankj.utilcode.util.FileIOUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;

public class ConfigManager {

    static ConfigManager configManager;

    public static ConfigManager instance() {
        if (configManager == null) {
            configManager = new ConfigManager();
            configManager.readFile();
        }
        return configManager;
    }

    public ConfigInfo configInfo;

    private void readFile() {
        String path = Environment.getExternalStorageDirectory() + "/AIOD/config.txt";
        String text = FileIOUtils.readFile2String(path);
        Log.i("text:" + text);
        if (!TextUtils.isEmpty(text)) {
            configInfo = new Gson().fromJson(text, ConfigInfo.class);
//            ToastUtils.showLong("已读取配置文件，使用文件配置");

        } else {
            configInfo = new ConfigInfo();
//            ToastUtils.showLong("未获取配置文件，使用默认配置");
        }
        Log.i("配置:"+ new Gson().toJson(new ConfigInfo()));

    }


}
